package com.ivi.car.module.city.view.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ivi.car.R;
import com.ivi.car.module.city.model.CityInfo;

import java.util.List;

/**
 * 热门城市显示
 */

public class HotCityAdapter  extends BaseAdapter {
    private final List<CityInfo> hotList;
    private final LayoutInflater inflater;
    public HotCityAdapter(List<CityInfo> cityHotList, LayoutInflater inflater) {
        this.hotList = cityHotList;
        this.inflater = inflater;
    }
    @Override
    public int getCount() {
        if (hotList.size() == 0) {
            return 0;
        } else {
            return hotList.size();
        }
    }
    @Override
    public Object getItem(int position) {
        return hotList.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_hot_city, parent, false);
            holder.hotCityName = convertView.findViewById(R.id.city_hot_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CityInfo info = hotList.get(position);
        holder.hotCityName.setText(info.getName());
        return convertView;
    }

    /**
     * ViewHolder
     */
    class ViewHolder {
        TextView hotCityName;
    }
}
